var savebtn = false;
function confirm_apply() {
    if(savebtn)
        return;
    else
        savebtn = true;
    var token = $("#token").val();
    if (isempty(token)) {
        location.href = "/except/login.jsp";
        return;
    } else {
        var jsonstr = "{token:" + token + "}";
        var name = $("#name").val();
        var card = $("#card").val();
        if(isempty(name)) {
            $("#hintbg").show();
            $("#hint_message").html("请输入名字");
            savebtn = false;
            return;
        }
        if(isempty(card)) {
            $("#hintbg").show();
            $("#hint_message").html("请输入身份证号");
            savebtn = false;
            return;
        }
        var url = "/except/usercontroller/authapply.action";
        $.ajax({
            url: url,
            type: 'post',
            dataType: "json",
            data: {
                json: jsonstr,
                name : name,
                card:card,
            },
            async: false,
            success: function (data) {
                var code = data.code;
                var message = data.message
                if (code == 20000) {
                    $("#hintbg").show();
                    $("#hint_message").html("绑定成功");
                    flag = true;
                    remove_advertising();
                } else if(code == 10001 || code == 10002)
                    location.href = '/except/login.jsp';
                else {
                    $("#hintbg").show();
                    $("#hint_message").html(message);
                    savebtn = false;
                }
            }
        });
    }
}

$(function () {
    var token = $("#token").val();
    if (isempty(token)) {
        location.href = "/except/login.jsp";
        return;
    } else {
        var jsonstr = "{token:" + token + "}";
        var url = "/except/usercontroller/getuserauth.action";
        $.ajax({
            url: url,
            type: 'post',
            dataType: "json",
            data: {
                json: jsonstr
            },
            async: false,
            success: function (data) {
                var code = data.code;
                var message = data.message
                if (code == 20000) {
                    $("#name").val(data.data.name);
                    $("#card").val(data.data.card);
                    $("#save").hide();
                } else if(code == 20013){

                } else if(code == 10001 || code == 10002)
                    location.href = '/except/login.jsp';
                else {
                    $("#hintbg").show();
                    $("#hint_message").html(message);
                }
            }
        });
    }
    $("#confirm_btn").click(function () {
        location.href = "/except/files/userinfo.jsp";
    });
});
